package controller;

import model.HealMedicine;
import model.Item;
import model.StrengthenMedicine;
import model.Weapon;

import java.io.IOException;
import java.util.HashMap;

public class ItemController {
    static HashMap<String, Item>items=new HashMap<>();

    public static void listItems(){
        Weapon item1=new Weapon(1,"匕首","Weapon","一把锋利的匕首，也许会很有用。",0,5,10,0,
                "");
        Weapon item2=new Weapon(1,"枪","Weapon","七步以外枪快。",0,10,20,0,"");
        StrengthenMedicine item3=new StrengthenMedicine(10,"经验药水","StrengthenMedicine","可以提升经验。",
                100,0,0,0,0,"");
        HealMedicine item4=new HealMedicine(1,"治疗药水","HealMedicine","愿司辰治愈你的伤势。",10,0,0,
                "");
        StrengthenMedicine item5=new StrengthenMedicine(1,"体质药水","StrengthenMedicine","可以提升体质。",
                0,10,0,0,0,"");
        StrengthenMedicine item6=new StrengthenMedicine(1,"敏捷药水","StrengthenMedicine","可以提升敏捷。",
                0,0,10,0,0,"");
        StrengthenMedicine item7=new StrengthenMedicine(1,"力量药水","StrengthenMedicine","可以提升力量。",
                0,0,0,10,0,"");
            items.put(item1.getName(),item1);
            items.put(item2.getName(),item2);
            items.put(item3.getName(),item3);
            items.put(item4.getName(),item4);
            items.put(item5.getName(),item5);
            items.put(item6.getName(),item6);
            items.put(item7.getName(),item7);
    }
    public static Item getItem(String id){
        Item i= items.get(id);
        if(i==null){
            return null;
        }
        String type=i.getType();
        return switch (type) {
            case "StrengthenMedicine" -> new StrengthenMedicine((StrengthenMedicine) i);
            case "HealMedicine" -> new HealMedicine((HealMedicine) i);
            case "Weapon" -> new Weapon((Weapon) i);
            default -> null;
        };
    }
    public static void createItems() throws IOException {
        Weapon item1=new Weapon(1,"匕首","Weapon","一把锋利的匕首，也许会很有用。",0,5,10,0,
                "zhucheng");
        Weapon item2=new Weapon(1,"枪","Weapon","七步以外枪快。",0,10,20,0,"tiejibilei");
        StrengthenMedicine item3=new StrengthenMedicine(10,"经验药水","StrengthenMedicine","可以提升经验。",
                100,0,0,0,0,"zhucheng");
        HealMedicine item4=new HealMedicine(1,"治疗药水","HealMedicine","愿司辰治愈你的伤势。",10,0,0,
                "tiejibilei");
        StrengthenMedicine item5=new StrengthenMedicine(10,"体质药水","StrengthenMedicine","可以提升体质。",
                0,10,0,0,0,"rongzhuzhidu");
        StrengthenMedicine item6=new StrengthenMedicine(10,"敏捷药水","StrengthenMedicine","可以提升敏捷。",
                0,0,10,0,0,"huantuizhisen");
        StrengthenMedicine item7=new StrengthenMedicine(10,"力量药水","StrengthenMedicine","可以提升力量。",
                0,0,0,10,0,"xinyuanhuixiang");
        HealMedicine item8=new HealMedicine(3,"治疗药水","HealMedicine","愿司辰治愈你的伤势。",10,0,0,
                "rongzhuzhidu");
        HealMedicine item9=new HealMedicine(2,"治疗药水","HealMedicine","愿司辰治愈你的伤势。",10,0,0,
                "huantuizhisen");
        HealMedicine item10=new HealMedicine(5,"治疗药水","HealMedicine","愿司辰治愈你的伤势。",10,0,0,
                "xinyuanhuixiang");
        HealMedicine item11=new HealMedicine(1,"治疗药水","HealMedicine","愿司辰治愈你的伤势。",10,0,0,
                "huiguanghuilang");
        itemInit(item1);
        itemInit(item2);
        itemInit(item3);
        itemInit(item4);
        itemInit(item5);
        itemInit(item6);
        itemInit(item7);
        itemInit(item8);
        itemInit(item9);
        itemInit(item10);
        itemInit(item11);
    }
    public static void itemInit(Item item) {
        RoomController.getRoom(item.getLocation()).itemSet(item);
    }
}
